package com.idata.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;


@Configuration
public class RestTemplateConfig {

    @Value("${http.default.connectTimeout:50000}")
    private int defaultHttpConnectTimeout;
    @Value("${http.default.ReadTimeout:50000}")
    private int defaultHttpReadTimeout;

    @Value("${http.hotWords.connectTimeout:10000}")
    private int hotWordsHttpConnectTimeout;
    @Value("${http.hotWords.ReadTimeout:10000}")
    private int hotWordsHttpReadTimeout;

    /**
     * 默认 http 客户端
     * @return
     */
    @Bean(name = "restTemplate")
    public RestTemplate restTemplate() {
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        requestFactory.setConnectTimeout(this.defaultHttpConnectTimeout);
        requestFactory.setReadTimeout(this.defaultHttpReadTimeout);
        return new RestTemplate(requestFactory);
    }

    /**
     * 纠纷热词 http 客户端
     * @return
     */
    @Bean(name = "hotWordsRestTemplate")
    public RestTemplate hotWordsRestTemplate() {
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        requestFactory.setConnectTimeout(this.hotWordsHttpConnectTimeout);
        requestFactory.setReadTimeout(this.hotWordsHttpReadTimeout);
        return new RestTemplate(requestFactory);
    }
}
